package personal.xjl.studentdemo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import personal.xjl.studentdemo.dao.TeacherMapper;
import personal.xjl.studentdemo.service.StudentService;
import personal.xjl.studentdemo.service.TeacherService;

@Controller
@RequestMapping("/Login")
public class LoginController {
    @Autowired
    StudentService studentService;
    @Autowired
    TeacherService teacherService;
    @RequestMapping("login.do")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("passport") String passport, HttpSession session) {
        switch (passport){
            case "student":  {
                if(studentService.login(username,password)) {
                    //发放登录的令牌，username
                    session.setAttribute("username",username);
                    return "redirect:/Student/list.do";
                }
                else
                    return "login";
            }
            case "teacher":{
                if(teacherService.login(username,password)) {
                    //发放登录的令牌，username
                    session.setAttribute("username",username);
                    return "redirect:/Teacher/list.do";
                }
                else
                    return "login";
            }
            case "admin":
                break;
        }
        return "login";
    }
}
